const moment = {
  format: function(timestamp = null, dateOnly = false) {
    if (!timestamp) {
      return '';
    }
    const datetime = new Date(timestamp);
    const year = datetime.getFullYear();
    const month = this.pad(datetime.getMonth() + 1);
    const date = this.pad(datetime.getDate());
    const hour = this.pad(datetime.getHours());
    const minute = this.pad(datetime.getMinutes());
    const second = this.pad(datetime.getSeconds());
    const d = [year, month, date];
    const t = [hour, minute, second];
    const res = dateOnly ? d.join('-') : `${d.join('-')} ${t.join(':')}`;
    return res;
  },

  pad: function(value) {
    return value.toString().padStart(2, '0');
  },
};

export {
  moment,
};
